<?php
/**
 * Description of addTreaties
 *
 * @author Runner
 */

class addTreatiesInfo extends AddInformation{
    private $treaties;
    private $queryStr;
    
    function __construct($treaties=null) {
        $this->treaties = $treaties;
        $this->queryStr = sprintf('insert into Treaties(name, source, author, year, auditingState)'.
                                        'values("%s", "%s", "%s", "%s", "%s")', 
                                        $this->treaties->name, $this->treaties->source,
                                        $this->treaties->author, $this->treaties->year,
                                        $this->treaties->auditingState
                                    );
        
    }
    
    public function add($linkIdentify) {
        if($this->check()){
            if($this->addInfo($this->queryStr, $linkIdentify)){
                return true;
            }
            return false;
        }
    }
    
    /* 检查数据是否合格 */
    function check(){
        if($this->treaties==NULL){
            return false;
        }
        /* 检查是否为空字符串 */
        foreach (AttributesName::$treaties as $value) {
            if($this->treaties->$value==""){
                return false;
            }
        }
        /* 检查是否符合字符串要求 */
        if(true){
            /* 匹配日期 */
            $timePattern = '/[0-9]{4}/';       // 日期的正则表达式模式
            if( preg_match($timePattern, $this->treaties->year)==0 ){
                return false;
            }
        }
        return true;
    }
}
